import { defHttp } from '/@/utils/http/axios';
import { PageResult } from '@/api/model/pageResult';
import { ContentTypeEnum } from '@/enums/httpEnum';
import { QueryMakeMethodBo } from '@/api/base-data/make/model/queryMakeMethodBo';
import { GetMakeMethodBo } from '@/api/base-data/make/model/getMakeMethodBo';
import { CreateMakeMethodVo } from '@/api/base-data/make/model/createMakeMethodVo';
import { UpdateMakeMethodVo } from '@/api/base-data/make/model/updateMakeMethodVo';
import { QueryMakeMethodVo } from '@/api/base-data/make/model/queryMakeMethodVo';
import { CreateProductMakeVo } from '@/api/base-data/make/model/createProductMakeVo';
import { ProductMakeBo } from '@/api/base-data/make/model/productMakeBo';

const baseUrl = '/basedata/make';
const region = 'cloud-api';

/**
 * 查询列表
 * @param params
 * @returns {Promise}
 */
export function query(params: QueryMakeMethodVo): Promise<PageResult<QueryMakeMethodBo>> {
  return defHttp.get<PageResult<QueryMakeMethodBo>>(
    {
      url: baseUrl + '/query',
      params: params,
    },
    {
      region,
    },
  );
}

/**
 * 根据ID查询
 * @param id
 * @returns {Promise}
 */
export function get(id: String): Promise<GetMakeMethodBo> {
  return defHttp.get<GetMakeMethodBo>(
    {
      url: baseUrl,
      params: {
        id,
      },
    },
    {
      region,
    },
  );
}

/**
 * 新增
 * @param params
 * @returns {Promise}
 */
export function create(params: CreateMakeMethodVo): Promise<void> {
  return defHttp.post<void>(
    {
      url: baseUrl,
      data: params,
    },
    {
      contentType: ContentTypeEnum.JSON,
      region,
    },
  );
}

/**
 * 修改
 * @param params
 * @returns {Promise}
 */
export function update(params: UpdateMakeMethodVo): Promise<void> {
  return defHttp.put<void>(
    {
      url: baseUrl,
      data: params,
    },
    {
      contentType: ContentTypeEnum.JSON,
      region,
    },
  );
}

/**
 * 保存商品与制作方法关系
 * @param makeId
 * @param params
 * @returns {Promise}
 */
export function createProductMake(makeId: string, params: CreateProductMakeVo[]): Promise<void> {
  return defHttp.post<void>(
    {
      url: baseUrl + `/product/${makeId}`,
      data: params,
    },
    {
      contentType: ContentTypeEnum.JSON,
      region,
    },
  );
}

/**
 * 根据制作方法ID获取关联商品
 * @returns {Promise}
 * @param makeId
 */
export function getProductMake(makeId: String): Promise<ProductMakeBo[]> {
  return defHttp.get<ProductMakeBo[]>(
    {
      url: baseUrl + `/product/${makeId}`,
    },
    {
      region,
    },
  );
}
